/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webResource;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import model.Booking;
import model.Client;
import model.Flight;
import model.FlightsAndClient;

/**
 * REST Web Service
 *
 * @author Jorge
 */
@Path("bookingManagement")
public class ServiceBookingManagement {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of ServiceBookingManagement
     */
    public ServiceBookingManagement() {
    }

    /**
     * Retrieves representation of an instance of webResource.ServiceBookingManagement
     * @return an instance of java.lang.String
     */
    @PUT
    @Path("generateBooking")
    @Consumes("application/json")
    @Produces("application/json")
    public Booking generateBooking(FlightsAndClient flightsAndClient)  {
      // Generated booking		
		Booking booking = new Booking(flightsAndClient.getSelectedFlights()[0],
                        flightsAndClient.getSelectedFlights()[1], flightsAndClient.getClient());
		
		// Generates a random 8-letter (upper-cased) booking code
		char[] bookingChar = new char[8];
		for (int i = 0; i < 8; i++)
			bookingChar[i] = (char)(65 + (int)(25 * Math.random()));	// Random integer between 65 (A) and 90 (Z)
		booking.setBookingCode(new String(bookingChar));
		
		/* FIXME It is necessary to handle the selected flight class and respective value to be paid 
		 * (since the value depends on the chosen class) and additional information */
		return booking;
    }
    
    @PUT
    @Path("selectFlights")
    @Consumes("application/json")
    @Produces("application/json")
    public Flight[] selectFlights(Flight[] availableFlights) 
	{
		// FIXME Implement this method
		return availableFlights;
	}

   
   
}
